<?php

function get_tag_list($con)
{
	$query = "SELECT * FROM tag";
	return select($con, $query);
}

function get_tag($con, $id)
{
	$query = "SELECT tag.* FROM tag " .
		"WHERE tag.id = '$id'";
	$records = select($con, $query);
	if(count($records != 1))
		return NULL;
	return select($con, $query);
}

function insert_tag($con, $tag)
{
	$paradise_id = $tag["paradise_id"];
	$name = $tag["name"];
	$type = $tag["type"];
	$rating = $tag["rating"];

	$query = "INSERT INTO tag(paradise_id, name, type, rating) " .
		"VALUES('$paradise_id', '$name', '$type', '$rating')";
	return insert($con, $query);
}

function update_tag($con, $tag)
{
	$id = $tag["id"];
	$paradise_id = $tag["paradise_id"];
	$name = $tag["name"];
	$type = $tag["type"];
	$rating = $tag["rating"];

	$query = "UPDATE tag SET  name = '$name', type = '$type', rating = '$rating' " .
		"WHERE id = '$id'";
		error_log($query);

	return update($con, $query);
}

function get_paradise_tags($con,$paradise_id){
	$query="select * from tag where paradise_id=$paradise_id";
	return select($con,$query);
}

function get_tag_paradise_name($con,$tag){
		$paradise_id=$tag['paradise_id'];
		$name=$tag['name'];
		$query="select * from tag where paradise_id=$paradise_id and name='$name'";
		return select($con,$query);
	
}

function tag_exists($con,$tag){
	$paradise_id=$tag['paradise_id'];
	$name=$tag['name'];
	$query="select * from tag where paradise_id='$paradise_id' and name='$name'";
	$list=select($con,$query);
	if($list){
		error_log("HERE");
		return true;
	}else {
		return false;
	}
}

function get_all_tags_for_paradise($con,$paradise_id_list){
	$query="select DISTINCT tag.name from tag where tag.paradise_id in ($paradise_id_list)";
	return select($con,$query);

}
